<%@ page contentType="text/html;charset=UTF-8" %>

<!DOCTYPE html>
<html>
<head>
	<title>接口注册管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/demo.css">
	<script type="text/javascript">
		$(function(){
			$('#dataCateList').datagrid({
				title:'接口注册列表',
				iconCls:'icon-ok',
				url:'${ctx }/protocol/list!data.action',
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,20,30,50],
				idField:'registerId',
				columns:[[
                    {field:'beanName',title:'注册bean名称',width:120,sortable:true},
					{field:'beanId',title:'注册beanID',width:100,sortable:true},
					{field:'methodName',title:'方法标识',width:120,sortable:true},
					{field:'callType',title:'协议',width:80,sortable:true,
						formatter:function(value){
							if( value=='http'){return '<font color=blue>http协议</font>';}
							else if( value=='https'){return '<font color=blue>https协议</font>';}
							else if( value=='socket'){return '<font color=blue>socket协议</font>';}
							else if( value=='webservice'){return '<font color=blue>webservice协议</font>';}
							else{ return '<font color=red>内部协议</font>';}
						}
					},
					{field:'address',title:'访问地址',width:60,sortable:true},
					{field:'port',title:'访问端口',width:50,sortable:true},
					//{field:'createdTime',title:'创建时间',width:120,sortable:true},
					{field:'flag',title:'状态',width:20,sortable:true,
						formatter:function(value){
							if( value=='1'){return '<font color=blue>启用</font>';}
							else{ return '<font color=red>停用</font>';}
						}
					}
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveCate();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteCate();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editCate();
					}
				},'-',{
					text:'查找',
					iconCls:'icon-search',
					handler:function(){
						$('#query').window('open');
					}
				},'-',{
					text:'刷新缓存',
					iconCls:'icon-search',
					handler:function(){
						editCache();
					}
				},'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
						$('#dataCateList').datagrid('reload');
					}
				}
				],
				onDblClickRow:function(){
					dataItemTree();
				}	
			});		
		});
		
		// 查找
		function searchCate(){
			var queryParams = $('#dataCateList').datagrid('options').queryParams;	       
	        queryParams.beanId = $('#beanId').val();
	        queryParams.beanName = $('#beanName').val();
	        var options = $('#dataCateList').datagrid('getPager').data("pagination").options;  
	        options.pageNumber=1;  
	        options.total=0;  
	        options.pageSize=15; 
	        $('#dataCateList').datagrid("reload");
	        $('#query').window('close');
		}
		
		// 进入增加页面
		function saveCate(){
			$('#saveFrame').html('');			
			var url = '${ctx}/protocol/add.action';				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		function editCache(){
			$.ajax({
				type: "post",
				url: "${ctx}/protocol/cache.action",
				dataType: "json",
				success: function(data){
					var result = data;//jQuery.parseJSON(data);
					if(result.flag=='T'){
						$.messager.alert('结果', '操作成功', 'info');	
					}else if(result.flag=='H'){
						$.messager.alert('结果', result.msg, 'info');	
					}else{
						$.messager.alert('结果', '操作失败，请重试', 'error');	
					}
				},
				error:function(messg)  { 
		       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
		       } 
			});
		}
		
		
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		// 刷新列表
		function cateReload(){
			$('#dataCateList').datagrid('reload');
		}
		
		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#dataCateList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 进入修改页面
		function editCate(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/protocol/edit.action?id='+node.registerId;
				$('#saveFrame').attr("title",node.beanId);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		//删除，物理删除
		function deleteCate(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.beanId+'</font> ？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/protocol/del.action?id="+node.registerId,
							dataType: "json",
							success: function(data){
								var result = data;//jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info');	
								    var rowIndex = $('#dataCateList').datagrid('getRowIndex',node);								
								    $('#dataCateList').datagrid('deleteRow', rowIndex);	
	    						}else if(result.flag=='H'){
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error:function(messg)  { 
					       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
					       } 
						});
		          	}
		       });		             		
		    }	
		}

	</script>
</head>
<body>
	<table id="dataCateList"></table>
	<!-- 添加窗口 -->
	<div id="saveDiv" class="easyui-window" title="注册接口定义" style="padding:5px;width: 500px;height:300px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>

    <!-- 查询窗口 -->
	<div id="query" class="easyui-window" title="查询" style="padding:0px;width:400px;height:250;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		<table class="datagrid-body" >
		    <tr>	
				<td class="datagrid-header">注册bean名称：</td>
				<td><input type="text" id="beanName" name="beanName" size="30" value="" /></td>
			</tr>
			<tr>	
				<td class="datagrid-header">注册beanID：</td>
				<td><input type="text" id="beanId" name="beanId" size="30" value="" /></td>
			</tr>
			<tr>	
				<td colspan="2" align="center"><a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="searchCate();">查找</a></td>	
			</tr>
		</table>
    </div>
</body>
</html>